char vector_i[14][10];
char buffer10[100];
int index, h;
void initializare_v(char a[14][10])
{
	for(int i=0; i<nr_cuvinte; i++)
	{
		char x[3];
		x[0]=i+48;
		x[1]='\0';
		strcpy(vector_i[i],x);
		strcat(vector_i[i],a[i]);
	}
}
tree_index *root;
void search_RSD(tree_index *root, int index)
{
	if(root==NULL)
		return;
	if(root->apare==true && root->index==index)
		h=root->val;
	else
	{
		search_RSD(root->left, index);
		search_RSD(root->right, index);
	}
}	
int find()
{
	int v[10];
	int m=0;
	int ok=0;
	for(int i=0; i<nr_cuvinte; i++)
		{
			char *p=(char *)malloc(sizeof(char));
			strcpy(p, a[i]);
			if(strcmp(p, find_c)==0)
			{
				index=vector_i[i][0]-48+1;
				ok=1;
				v[m]=index+1;
				m++;
				search_RSD(tree, index);
			}

		}
	char sir[50]="Cuvantul ";
	strcat(sir, find_c);
	if(m<=1)
		strcat(sir, " se afla pe pozitia ");
	else
		strcat(sir, " se afla pe pozitiile ");
	for(int i=0; i<m; i++)
	{
		char c[5];
		c[0]=v[i]+48-1;
		c[1]='\0';
		if(m>=1 && i!=m-1)
			strcat(c, ", ");
		strcat(sir, c);
	}
	sprintf(buffer10, "%s", sir);
	return ok;
}
void adaugare(tree_index *root)
{
	if(root==NULL)
		return;
	else
		if(root->left==NULL && root->right==NULL)
		{
			root->left=(tree_index *)malloc(sizeof(tree_index));
			root->left->left=NULL;
			root->left->right=NULL;
			root->right=(tree_index *)malloc(sizeof(tree_index));
			root->right->left=NULL;
			root->right->right==NULL;
		}
		else
		{
			adaugare(root->left);
			adaugare(root->right);
		}
}
void stergere(tree_index *root, tree_index *nod_c, char delete_c[20], int s_c)
{
	if(root==NULL || root->left==NULL || root->right==NULL || root->right->apare==false || root->left->apare==false)
	//{
		//if(root==NULL)
			return;
	//	if(strcmp(root->str, delete_c)==0)
	//	{
	//		root->apare=false;
	//		root=NULL;
	//	}
	//}
	else
	{
		stergere(root->left, nod_c, delete_c, s_c);
		int i;
		if(strcmp(root->left->str,delete_c)==0)
			if(root->right->left!=NULL || root->right->right!=NULL)
			{
				if(root->right->left->apare!=false && root->right->right->apare!=false)
				{
					i=root->left->index;
					for(i; i<s-1; i++)
						strcpy(a[i], a[i+1]);
					strcpy(a[s-1], "");
					s--;
					strcpy(root->str, root->right->str);
					strcpy(root->right->str, root->right->right->str);
					strcpy(root->left->str, root->right->left->str);
					root->right->left->apare=false;
					//root->right->left=NULL;
					root->right->right->apare=false;
					da=1;
					//root->right->right=NULL;
				}
				else
				{
					if(root->right->apare!=false)
					{
						nod_c=root->right;
						da=1;
					}
					i=root->left->index-(s_c-s)-1;
				}
			}
			else
			{
				if(root->right->apare!=false)
				{
					nod_c=root->right;
					da=1;
				}
				i=root->left->index-(s_c-s)-1;
			}
		if(strcmp(root->right->str, delete_c)==0)
			if(root->left->right!=NULL || root->left->left!=NULL)
			{
				if(root->left->right->apare!=false && root->left->left!=false)
				{
					i=root->right->index;
					for(i; i<s-1; i++)
						strcpy(a[i], a[i+1]);
					strcpy(a[s-1], "");
					s--;
					strcpy(root->str, root->left->str);
					strcpy(root->right->str, root->left->right->str);
					strcpy(root->left->str, root->left->left->str);
					root->left->left->apare=false;
					//root->left->left=NULL;
					root->left->right->apare=false;
					da=1;
					//root->left->right=NULL;
				}
				else
				{
					if(root->left->apare!=false)
					{
						nod_c=root->left;
						da=1;
					}
					i=root->right->index-(s_c-s)-1;
				}
			}
			else
			{
				if(root->left->apare!=false)
				{
					nod_c=root->left;
					da=1;
				}
				i=root->right->index-(s_c-s)-1;
			}	
		if(nod_c!=NULL)
		{
			for(i; i<s-1; i++)
				strcpy(a[i], a[i+1]);
			strcpy(a[s-1], "");
			s--;
			strcpy(root->str, nod_c->str);
			root->left->apare=false;
			//root->left=NULL;
			root->right->apare=false;
			//root->right=NULL;
			nod_c==NULL;
			da=1;
		}
		stergere(root->right, nod_c, delete_c, s_c);
	}
}
void recreate(tree_index *root1, tree_index *root2)
{
	if(root2==NULL)
		return;
	else
	{
		strcpy(root1->str, root2->str);
		root1->index=root2->index;
		tree_index *p=(tree_index *)malloc(sizeof(tree_index));
		p->apare=false;
		root1->left=root1->right=p;
		root1->apare=true;
		recreate(root1->left, root2->left);
		recreate(root1->right, root2->right);
	}
}
void stergere2(tree_index *root, char delete_c[20], int s_c)
{
	if(root->left==NULL || root->right==NULL)
		return;
	else
	{
		if(strcmp(root->left->str, delete_c)==0)
			recreate(root, root->right);
		if(strcmp(root->right->str, delete_c)==0)
			recreate(root, root->left);
		stergere2(root->left, delete_c, s_c);
		stergere2(root->right, delete_c, s_c);
	}
}





								

		